﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

namespace Maticsoft.Common
{
    public class HttpPost
    {
        public string HttpWebPost(string requestUriString, string value)
        {
            StreamWriter requestWriter = null;
            StreamReader responseReader = null;

            string responseData = "";
            HttpWebRequest webRequest = WebRequest.Create(requestUriString) as HttpWebRequest;
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ServicePoint.Expect100Continue = false;
            webRequest.Timeout = 20000;
            Stream responseStream = null;

            try
            {
                //POST the data.
                requestWriter = new StreamWriter(webRequest.GetRequestStream());
                requestWriter.Write(value);
                requestWriter.Close();
                responseStream = webRequest.GetResponse().GetResponseStream();
                responseReader = new StreamReader(responseStream);
                responseData = responseReader.ReadToEnd();
                responseStream.Close();
                responseStream.Dispose();
                responseReader.Close();
                responseReader.Dispose();
                requestWriter = null;
                return responseData;
            }
            catch (Exception ex)
            {
                return "error";
            }
        }
    }
}
